using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class OrderProcessMap : EntityTypeConfiguration<OrderProcess>
    {
        public OrderProcessMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            this.Property(t => t.Note)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("OrderProcess");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.Status).HasColumnName("Status");

            // Relationships
            this.HasOptional(t => t.Order)
                .WithMany(t => t.OrderProcesses)
                .HasForeignKey(d => d.OrderID);
            this.HasOptional(t => t.ProductModel)
                .WithMany(t => t.OrderProcesses)
                .HasForeignKey(d => d.ProductModelID);

        }
    }
}
